<template>
  <div>
    <div class="showTitle" v-if="item.comingTitle">{{item.comingTitle}}</div>
    <div class="movieItem" v-longpress="showSlideMenu" :data-id="item.id" @click="goDetail">
      <div class="left">
        <img @click.stop="previewImage(index)" v-lazy="item.img.replace('w.h','128.180')" alt />
      </div>
      <ul class="center">
        <li class="nm">{{item.nm}}</li>
        <li class="sc" v-if="item.globalReleased">
          评分
          <span>{{item.sc}}</span>
        </li>
        <li class="sc" v-else>
          <span>{{item.wish}}</span>人想看
        </li>
        <li>{{item.star}}</li>
        <li>{{item.showInfo}}</li>
      </ul>
      <div class="right">
        <button type="button" class="btnBy" v-if="item.globalReleased" @click.stop="byTicket">购票</button>
        <button type="button" class="btnYs" v-else>预售</button>
      </div>
    </div>
  </div>
</template>
<script>
import { mapActions } from "vuex";
export default {
  name: "MovieItem",
  props: ["item", "index"],
  methods: {
    ...mapActions(["showMenu"]),
    previewImage(index) {
      //利用事件冒泡去执行父级的showImage事件
      this.$emit("showImage", this.index);
    },
    goDetail(event) {
      this.$router.push({
        path: `/Detail/${event.currentTarget.dataset.id}`
      });
    },
    showSlideMenu(event) {
      let arr = ["收藏列表", "查看详细"];
      let that = this;
      event.preventDefault();
      this.showMenu({
        itemList: arr,
        success: function(index) {
          if (index == 1) {
            that.$router.push({
              path: `/Detail/${event.click.dataset.id}`
            });
          }
        }
      });
    },
    byTicket() {
      this.$confirm("你确定要买票吗?");
    }
  }
};
</script>
<style lang="scss" scoped>
.showTitle {
  margin: 0.08rem;
  font-size: 0.36rem;
  color: gray;
}
.movieItem {
  display: flex;
  box-sizing: border-box;
  padding: 0.08rem;
  border-bottom: 1px solid #ececec;
  .left {
    width: 1.6rem;
    img {
      width: 100%;
    }
  }
  .center {
    flex: 1;
    margin: 0;
    padding: 0;
    list-style-type: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    margin-left: 0.2rem;
    font-size: 0.24rem;
    color: gray;
    .nm {
      font-size: 0.36rem;
      font-weight: bold;
      color: black;
    }
    .sc {
      > span {
        font-size: 0.36rem;
        color: orange;
      }
    }
  }
  .right {
    width: 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    .btnBy {
      width: 1.2rem;
      height: 0.6rem;
      background: var(--pColor);
      border: none;
      outline: none;
      border-radius: 0.1rem;
      font-size: 0.28rem;
      color: white;
    }
    .btnYs {
      @extend .btnBy;
      background: #3c9fe6;
    }
  }
}
</style>